package news.service;

import news.dao.LinksDao;
import news.model.Admin;
import news.model.Link;
import news.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
@Transactional
public class LinksService {
    @Autowired
    LinksDao linksDao;
    public List<Link> linkList(Link link){
        List<Link> links = linksDao.linkList(link);
        return links;
    }

    public void changeStatus(Integer id, Integer status) {
        linksDao.changeStatus(id,status);
    }

    public void delete(Integer id) {
        linksDao.deleteLinks(id);
    }

    public void save(Link link, String adminToken) {
        link.setAdmin(JWTUtil.getAdminByToken(adminToken));
        linksDao.save(link);
    }

    public Link findLinkById(Integer id) {
        Link link = linksDao.findLinkById(id);
        return link;
    }

    public void update(Link link, String adminToken) {
        link.setAdmin(JWTUtil.getAdminByToken(adminToken));
        linksDao.update(link);
    }
}
